export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        console.log('papap')
        try {
            const { sheet, col: deleteCol, table } = options;
            sheet.suspendPaint();
            const { row: dataRow } = table.dataRange();
            if (isUndo) {
                const { name, row:olRow, col, rowCount, colCount, columns, cellTypes, bindingPath, showHeader,deleteCol, columnsWith } = options.old;
                sheet.addColumns(deleteCol,1);
                sheet.setColumnWidth(deleteCol,columnsWith);
                sheet.tables.resize(table,rowCount, colCount);
                for (let row = olRow;  row < rowCount; row++) {
                        let cell = sheet.getCell(row, deleteCol);
                        cell.cellType(options._oldCellTypes[row][deleteCol])
                            .backColor(options._oldBackColor[row][deleteCol])
                            .textIndent(options._oldTextIndent[row][deleteCol])
                            .backgroundImageLayout(options._oldBackgroundImageLayout[row][deleteCol])
                            .backgroundImage(options._oldBackGroundImage[row][deleteCol])
                            .value(options._oldValue[row][deleteCol]);
                    
                }
                if(options._oldSpans) {
                    options._oldSpans.forEach(range => {
                        sheet.addSpan(range.row, range.col, range.rowCount, range.colCount);
                    });
                }
                
                // sheet.tables.remove(name);
                // const oldTable = sheet.tables.add(name, row, col, rowCount, colCount, undefined, { showHeader });
                // oldTable.filterButtonVisible(false);
                // oldTable.bindColumns(columns.map(column => new GC.Spread.Sheets.Tables.TableColumn(column.dataField).name(column.name).dataField(column.dataField)));
                // oldTable.bindingPath(bindingPath);
                // cellTypes.forEach((cellType, index) => {
                //     sheet.getCell(dataRow, col + index)
                //         .cellType(cellType)
                //         .textIndent(2.5)
                //         .backgroundImageLayout(GC.Spread.Sheets.ImageLayout.none)
                //         .backgroundImage(cellType.getFieldTypeImage());
                // });
            } else {
                const { row:oldRow, col, name, rowCount, colCount, columns, bindingPath, showHeader } = table.toJSON();
                options.old = {
                    name, row:oldRow, col, rowCount, colCount, columns, bindingPath, showHeader,deleteCol, columnsWith : sheet.getColumnWidth(deleteCol)
                };
                
            //     const newColumns = [];
            //     const newCellTypes = [];
            //     columns.forEach((column, index) => {
            //         const tempCol = col + index;
            //         const cell = sheet.getCell(dataRow, tempCol);
            //         if (tempCol !== deleteCol) {
            //             newColumns.push(column);
            //             newCellTypes.push(cell.cellType());
            //         }
            //     });

            //     sheet.tables.remove(name);
            //     if (colCount > 1) {
            //         const oldTable = sheet.tables.add(name, row, col, rowCount, colCount - 1, undefined, { showHeader });
            //         oldTable.filterButtonVisible(false);
            //         oldTable.bindColumns(newColumns.map(column => new GC.Spread.Sheets.Tables.TableColumn(column.dataField).name(column.name).dataField(column.dataField)));
            //         oldTable.bindingPath(bindingPath);
            //     }

            //     newCellTypes.forEach((cellType, index) => {
            //         sheet.getCell(dataRow, col + index).cellType(cellType)
            //             .textIndent(2.5)
            //             .backgroundImageLayout(GC.Spread.Sheets.ImageLayout.none)
            //             .backgroundImage(cellType.getFieldTypeImage());
            //     });
            //     sheet.getCell(dataRow, col + colCount - 1)
            //         .cellType(undefined)
            //         .textIndent(0)
            //         .backgroundImageLayout(GC.Spread.Sheets.ImageLayout.none)
            //         .backgroundImage(undefined);
                options._oldBackColor = {};
                options._oldCellTypes = {};
                options._oldBackGroundImage = {};
                options._oldBackgroundImageLayout = {};
                options._oldTextIndent = {};
                options._oldValue = {};
                    for (let row = oldRow; row < rowCount; row++) {
                        if (!options._oldBackColor[row]) {
                            options._oldBackColor[row] = {}
                        }
                        if (!options._oldCellTypes[row]) {
                            options._oldCellTypes[row] = {};
                        }
                        if (!options._oldTextIndent[row]) {
                            options._oldTextIndent[row] = {};
                        }
                        if (!options._oldBackGroundImage[row]) {
                            options._oldBackGroundImage[row] = {};
                        }
                        if (!options._oldBackgroundImageLayout[row]) {
                            options._oldBackgroundImageLayout[row] = {};
                        }
                        if (!options._oldValue[row]) {
                            options._oldValue[row] = {};
                        }
                            let cell = sheet.getCell(row, deleteCol);
                            
                            options._oldBackColor[row][deleteCol] = cell.backColor();
                            options._oldCellTypes[row][deleteCol] = cell.cellType();
                            options._oldTextIndent[row][deleteCol] = cell.textIndent();
                            options._oldBackGroundImage[row][deleteCol] = cell.backgroundImage();
                            options._oldBackgroundImageLayout[row][deleteCol] = cell.backgroundImageLayout();
                            options._oldValue[row][deleteCol] = cell.value();
                            const span = sheet.getSpan(row, col);
                            if (span && span.row === row && span.col === col) {
                                if (!options._oldSpans) {
                                    options._oldSpans = [];
                                }
                                options._oldSpans.push(span);
                            }
                        
                    }

                sheet.deleteColumns(deleteCol,1);
                console.log(deleteCol,"删除的列")
                sheet.tables.resize(table,rowCount, colCount-1);
             }
            sheet.resumePaint();
        } catch (e) {
            if (!!(window.console && window.console.log)) {
                window.console.log(e);
            }
        }
    }
};